package com.lr.dao.Product.impl;

import com.lr.dao.Product.ProductDao;
import com.lr.domain.Product;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.ResultSetExtractor;
import org.springframework.stereotype.Repository;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
@Repository("product")
public class productDaoimpl  implements ProductDao {
     @Autowired
    @Qualifier("jdbcTemplate")
    JdbcTemplate jdbcTemplate;
    public List<Product> ListProduct() {
    class productres implements ResultSetExtractor<List<Product>>
    {


        public List<Product> extractData(ResultSet resultSet) throws SQLException, DataAccessException {
            List<Product> list=new ArrayList<Product>();
                while(resultSet.next()) {
                    Product product=new Product();
                    product.setId(resultSet.getInt("id"));
                    product.setName(resultSet.getString("name"));
                    product.setPrice(resultSet.getFloat("price"));
                     list.add(product);

            }

return list;


        }
    }





        return jdbcTemplate.query("select id,name, price from product",new productres());
    }

}
